#ifndef SQLMGR_H
#define SQLMGR_H

#include <QString>
#include <QVector>
#include <QSqlDatabase>

//设计SqlMgr: 单例模式,方便全局调用
class SqlMgr
{
public:
    ~SqlMgr();

public:
    static SqlMgr* getInstance() {
        if(instance == nullptr) {
            instance = new SqlMgr();
        }
        return instance;
    }

public:
    void init();

    //用户登录
    bool login(QString strUser,QString strPass,int &Userid);
    //获取所有用户
    QVector<QStringList> getUser(QString strCondition = "");
    //添加用户
    void addUser(QVector<QStringList> v);
    //删除用户
    void delUser(QString strId);

    //获取所有图书
    QVector<QStringList> getBooks(QString strCondition = "");
    //增加图书
    void addBook(QVector<QStringList> vec);
    //修改图书
    void modifyBook(QStringList ldata);
    //删除图书
    QString delBook(QString strId);
    //归还图书
    QString returnBook(QString strUsrId, QString strBookId);
    //借阅图书
    QString borrowBook(QString strUsrId, QString strBookId);
    //获取借阅记录
    QVector<QStringList> getRecord(QString strCondition = "");
    //清空借阅记录
    void clearRecord();

private:
    SqlMgr();

private:
    QSqlDatabase m_db;

    static SqlMgr* instance;
};

#endif // SQLMGR_H
